import { defineStore } from 'pinia';

export const userStore = defineStore('user', {
	state: () => {
		return {
			userID: uni.getStorageSync('userId'),
			userInfo: uni.getStorageSync('userInfo') || {},
      userInfoExt:uni.getStorageSync('userInfoExt') || {},
			token: uni.getStorageSync('token') || '',
			lang: uni.getStorageSync('lang') || 'cn',
		};
	},
	actions: {
		setLang(lang) {
			this.lang = lang;
			uni.setStorage({
				key: 'lang',
				data: lang,
			});
		},
		setUserInfo(info) {
			this.userInfo = info;
			uni.setStorage({
				key: 'userInfo',
				data: info,
			});
		},
    setUserInfoExt(info){
      this.userInfoExt = info;
      uni.setStorage({
        key:'userInfoExt',
        data:info
      })
    },
		setToken(token) {
      uni.setStorageSync('token', token);
      this.token = token;
			/*uni.setStorage({
				key: 'token',
				data: token,
			});*/
		},
	},
});
